package com.gae.blore.client.dialog;

import com.gae.blore.client.domain.BusStop;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class BusDetailsDialog extends DialogBox {

	final Label routes = new Label("Routes");

	public BusDetailsDialog(BusStop busStop) {

		initWidget(busStop);
	}

	private void initWidget(BusStop busStop) {

		setText("Bus Stop Details");
		setAnimationEnabled(true);
		setModal(true);
		final Button closeButton = new Button("Close");

		// We can set the id of a widget by accessing its Element
		closeButton.getElement().setId("closeButton");
		String routesValue = busStop.getRoutes();

		final HTML routesVal = new HTML(null == routesValue ? "" : routesValue);

		final HTML sep = new HTML(":");

		FlexTable flexTable = new FlexTable();

		// Grid grid = new Grid(4, 3);
		PlaceFiller.fillPlace(busStop, flexTable);
		flexTable.setWidget(3, 0, routes);
		flexTable.setWidget(3, 1, sep);
		flexTable.setWidget(3, 2, routesVal);

		VerticalPanel dialogVPanel = new VerticalPanel();
		dialogVPanel.add(flexTable);
		// dialogVPanel.addStyleName("dialogVPanel");
		dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);

		HorizontalPanel horizontalPanel = new HorizontalPanel();
		horizontalPanel.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE);
		// horizontalPanel.s

		horizontalPanel.add(closeButton);
		dialogVPanel.add(horizontalPanel);
		setWidget(dialogVPanel);

		closeButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				BusDetailsDialog.this.hide();
			}
		});

	}
}
